//
//  CGameUI.cpp
//  MyPlaneGame
//
//  Created by yeates on 16/6/9.
//  Copyright (c) 2016年 yeates. All rights reserved.
//

#include "CGameUI.h"

CGameUI::CGameUI(){
    speed = 1;
    mpos = 0;
}

CGameUI::~CGameUI(){

}

void CGameUI::SetBgImage(IplImage *img){
    Bg = img;
    BgClone = cvCloneImage(Bg);
}

void CGameUI::Build(){
    mpos -= speed;
    if(mpos < 0)    mpos += Bg->height;
    for(int i = 0; i < Bg->height; i++){
        for(int j = 0; j < Bg->width; j++){
            int r,g,b;
            r = CV_IMAGE_ELEM(BgClone, uchar, (i + mpos)%Bg->height, j*3+0);
            g = CV_IMAGE_ELEM(BgClone, uchar, (i + mpos)%Bg->height, j*3+1);
            b = CV_IMAGE_ELEM(BgClone, uchar, (i + mpos)%Bg->height, j*3+2);
            
            CV_IMAGE_ELEM(Bg, uchar, i, j*3+0) = r;
            CV_IMAGE_ELEM(Bg, uchar, i, j*3+1) = g;
            CV_IMAGE_ELEM(Bg, uchar, i, j*3+2) = b;
        }
    }
}

void CGameUI::ShowBgImage(){
    cvShowImage("window",Bg);
}
IplImage* CGameUI::GetNowImage(){
    return Bg;
}